/*潜在客户*/
Ext.define('App.crm.potentialCustomersForm', {
    extend: 'Ext.window.Window',
    alias: 'widget.potentialCustomersForm',
    initComponent: function () {
        this.fields= new Ext.util.MixedCollection(),

        this.fields.add('state', new comboBox({
            name: 'state',
            dataIndex: 'state',
            fieldLabel: '状态',
            labelAlign: 'right',
            codeName: '潜在客户状态',
            queryMode: 'local',
            typeAhead: false,
            forceSelection: true,
            loadingText: '正在搜索...',
            allowBlank: false,
            hideTrigger: false
        }));
        this.fields.add('name', new Ext.form.TextField({
            name: 'name',
            dataIndex: 'name',
            fieldLabel: '姓名',
            allowBlank: false
        }));
        this.fields.add('phone', new Ext.form.TextField({
            name: 'phone',
            dataIndex: 'phone',
            fieldLabel: '手机',
            allowBlank: true
        }));
        this.fields.add('officePhone', new Ext.form.TextField({
            name: 'officePhone',
            dataIndex: 'officePhone',
            fieldLabel: '办公电话',
            allowBlank: true
        }));
        this.fields.add('company', new Ext.form.TextField({
            name: 'company',
            dataIndex: 'company',
            fieldLabel: '公司',
            allowBlank:false
        }));
        this.fields.add('email', new Ext.form.TextField({
            name: 'email',
            dataIndex: 'email',
            fieldLabel: '电子邮箱',
            allowBlank: true
        }));
        this.fields.add('position', new Ext.form.TextField({
            name: 'position',
            dataIndex: 'position',
            fieldLabel: '职务',
            allowBlank: true
        }));
        this.fields.add('hotSpot',new Ext.form.Checkbox({
            name: 'hotSpot',
            dataIndex: 'hotSpot',
            fieldLabel: '热点',
            labelAlign: 'right',
            inputValue: 1
        }));
        this.fields.add('numberOfEmployees', new Ext.form.NumberField({
            name: 'numberOfEmployees',
            dataIndex: 'numberOfEmployees',
            allowDecimals: false,
            decimalPrecision: null,
            fieldLabel: '职员数',
            allowBlank: true
        }));
        this.fields.add('source', new comboBox({
            name: 'source',
            dataIndex: 'source',
            fieldLabel: '来源',
            labelAlign: 'right',
            codeName: '来源',
            queryMode: 'local',
            typeAhead: false,
            forceSelection: true,
            loadingText: '正在搜索...',
            allowBlank: true,
            hideTrigger: false
        }));
        this.fields.add('annualTurnover', new Ext.form.NumberField({
            name: 'annualTurnover',
            dataIndex: 'annualTurnover',
            allowDecimals: true,
            decimalPrecision: 2,
            fieldLabel: '年营业额',
            allowBlank: true
        }));
        this.fields.add('industry', new comboBox({
            name: 'industry',
            dataIndex: 'industry',
            fieldLabel: '行业',
            labelAlign: 'right',
            codeName: '行业',
            queryMode: 'local',
            typeAhead: false,
            forceSelection: true,
            loadingText: '正在搜索...',
            allowBlank: true,
            hideTrigger: false
        }));
        this.fields.add('registeredCapital', new Ext.form.NumberField({
            name: 'registeredCapital',
            dataIndex: 'registeredCapital',
            allowDecimals: true,
            decimalPrecision: 2,
            fieldLabel: '注册资金',
            allowBlank: true
        }));
        this.fields.add('zip', new Ext.form.TextField({
            name: 'zip',
            dataIndex: 'zip',
            fieldLabel: '邮编',
            allowBlank: true
        }));
        this.fields.add('website', new Ext.form.TextField({
            name: 'website',
            dataIndex: 'website',
            fieldLabel: '网址',
            allowBlank: true
        }));
        this.fields.add('address', new Ext.form.TextField({
            name: 'address',
            dataIndex: 'address',
            fieldLabel: '地址',
            allowBlank: true
        }));

        this.fields.add('remark', new Ext.form.TextArea({
            name: 'remark',
            dataIndex: 'remark',
            fieldLabel: '备注',
            allowBlank: true
        }));
        var form = Ext.widget('form', {
            frame: false,
            border: true,
            split: true,
            autoScroll: true,
            bodyPadding: 5,
            bodyBorder: true,
            fieldDefaults: {
                labelWidth: 90,
                labelAlign: 'right',
                msgTarget: 'side'
            },
            defaults: {
                anchor: '100%'
            },
            items: [
                {
                    xtype: 'fieldset',
                    title: '潜在客户信息',
                    collapsible: true,
                    defaults: {
                        labelWidth: 89,
                        anchor: '100%',
                        layout: {
                            type: 'hbox',
                            defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                        }
                    },
                    items: [{
                        xtype: 'container',
                        layout: 'hbox', defaults: {
                            flex: 1,
                            hideLabel: true
                        },
                        margin: '0 0 5 0',
                        items:  [ this.fields.get('company'),this.fields.get('state')]},
                        {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            defaults: {
                                flex: 1,
                                hideLabel: true
                            },
                            items: [ this.fields.get('name'), this.fields.get('phone')]}, {
                            xtype: 'container',
                            layout: 'hbox', defaults: {
                                flex: 1,
                                hideLabel: true
                            },
                            margin: '0 0 5 0',
                            items: [ this.fields.get('officePhone'), this.fields.get('email')]}, {
                            xtype: 'container',
                            layout: 'hbox',
                            defaults: {
                                flex: 1,
                                hideLabel: true
                            },
                            margin: '0 0 5 0',
                            items: [ this.fields.get('position'), this.fields.get('hotSpot')]}
                    ]},
                {
                    xtype: 'fieldset',
                    title: '其他信息',
                    collapsible: true,
                    defaults: {
                        labelWidth: 89,
                        anchor: '100%',
                        layout: {
                            type: 'hbox',
                            defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                        }
                    },
                    items: [
                        {
                            xtype: 'container',
                            layout: 'hbox',
                            defaults: {
                                flex: 1,
                                hideLabel: true
                            },
                            margin: '0 0 5 0',
                            items: [ this.fields.get('numberOfEmployees'), this.fields.get('annualTurnover')]},

                        {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            defaults: {
                                flex: 1,
                                hideLabel: true
                            },
                            items: [  this.fields.get('source') ,this.fields.get('industry')]},
                        {
                            xtype: 'container',
                            layout: 'hbox',
                            margin: '0 0 5 0',
                            defaults: {
                                flex: 1,
                                hideLabel: true
                            },
                            items: [ this.fields.get('registeredCapital')]}
                    ]},
                {
                    xtype: 'fieldset',
                    title: '地址信息',
                    collapsible: true,
                    defaults: {
                        labelWidth: 89,
                        anchor: '100%',
                        layout: {
                            type: 'hbox',
                            defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                        }
                    },
                    items: [
                        {
                            xtype: 'container',
                            layout: 'hbox',
                            defaults: {
                                flex: 1,
                                hideLabel: true
                            },
                            margin: '0 0 5 0',
                            items: [this.fields.get('zip'),
                                this.fields.get('website')]},
                        this.fields.get('address')

                    ]},
                {
                    xtype: 'fieldset',
                    title: '备注',
                    collapsible: true,
                    defaults: {
                        labelWidth: 89,
                        anchor: '100%',
                        layout: {
                            type: 'hbox',
                            defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                        }
                    },
                    items: [this.fields.get('remark')]},
                {xtype: 'hidden',
                    name: 'id',
                    dataIndex: 'id'
                },
                {xtype: 'hidden',
                    name: 'deleteFlag',
                    dataIndex: 'deleteFlag'
                }

            ]
        });
        Ext.apply(this, {
            title: '新增',
            layout: 'fit',
            height: 500,
            width: 600,
            modal: true,
            constrain: true,
            closeAction: 'hide',
            buttonAlign: 'center',
            buttons: [
                {
                    text: "保存",
                    handler: function () {
                        //this.up(‘window’)获取了顶级的window组件。接着使用down()方法获取了window的子组件form组件，最后使用getForm()来获取整个form。
                        var form = this.up('potentialCustomersForm').down('form');
                        if (form.getForm().isValid()) {
                            form.getForm().submit({
                                url: getRootPath() + '/potentialCustomersController/save.action',
                                scope: form,
                                success: function (form, action) {
                                    this.up('potentialCustomersForm').close();
                                    Ext.getCmp('potentialCustomersGrid').getStore().reload();
                                },
                                failure: function (form, action) {
                                    if (action.result.message == undefined)
                                        Ext.Msg.alert('错误', '网络连接失败.');
                                    else
                                        Ext.Msg.alert('错误', action.result.message);
                                },
                                waitMsg: '保存数据...'
                            });
                        } else {
                            Ext.Msg.alert('提示', '表单含有无效或空数据');
                        }
                    }
                },
                {
                    text: "关闭",
                    handler: function () {
                        this.up('potentialCustomersForm').close();
                    }
                }
            ],
            items: form
        });

        this.callParent(arguments);
    }
});